package ServerStuff;

import java.io.IOException;
import java.net.HttpURLConnection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Database.DatabaseConnector;
import ExceptionClasses.InvalidReviewerAuthenticationException;

/**
 * Servlet implementation class RemoveSubscriptionServlet
 */
@WebServlet("/RemoveSubscriptionServlet")
public class RemoveSubscriptionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("in remove subscription servlet"); 
		
		DatabaseConnector db = new DatabaseConnector();
		 HttpSession session = request.getSession();
		 String busName = request.getParameter("busName");
		 try {
			 String subUser = (String) session.getAttribute("subUser");
			 String subPass = (String) session.getAttribute("subPass");
			 
			db.removeSubscription(subUser, subPass, busName);
			System.out.println("a remove has been done!");
			response.setStatus(HttpURLConnection.HTTP_ACCEPTED);
		} catch (InvalidReviewerAuthenticationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			response.setStatus(HttpURLConnection.HTTP_BAD_REQUEST);
		}
	}

}
